<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="等级编辑" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="会员等级:" prop="grade">
        {{ form.grade }}
      </el-form-item>
      <el-form-item label="会员名称:" prop="name">
        <el-input v-model="form.name" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="所需成长值:" prop="growth_value">
        <el-input v-model="form.growth_value" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="权益:" prop="equity">
        消费折扣<el-input v-model="form.equity" style="width: 100px;margin: 0 5px;"/>折
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="cancel">取消</el-button>
      <el-button :loading="loading" size="small" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  components: { },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        grade: '',
        name: '',
        growth_value: '',
        equity: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 表单验证
      this.$refs['form'].validate((valid) => {
        // 通过
        if (valid) {
          this.dialog = false
          this.form.equity = this.form.equity * 100
          this.$parent.editCallBack(this.form)
        }
      })
    },
    doAdd() {
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
